package com.atguigu.springcloud.comtroller;


import com.atguigu.springcloud.entities.CommonResult;
import com.atguigu.springcloud.entities.Payment;
import com.atguigu.springcloud.service.read.impl.PaymentReadServiceImpl;
import com.atguigu.springcloud.service.write.impl.PaymentWriteServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author hjl
 */
@RestController
@Slf4j
public class PaymentController {
    @Resource
    private PaymentReadServiceImpl readService;

    @Resource
    private PaymentWriteServiceImpl writeService;

    @PostMapping(value = "/payment/insert")
    public CommonResult insertPay(@RequestBody Payment payment){
        int insert = writeService.insert(payment);
        if (insert > 0 ){
            log.info("nb");
           return new CommonResult( 200,"成功",insert);

        }
        return new CommonResult(400,"失败",null);
    }

    @GetMapping(value = "/payment/list/{id}")
    public CommonResult selectById(@PathVariable(value = "id") Long id){
        Payment payment = readService.selectPaymentById(id);
        if (StringUtils.isEmpty(payment)){
            return new CommonResult(400,"失败",null);
        }
        return new CommonResult( 200,"成功",payment);
    }
}
